//
//  HYRootXiaoXiZhongXinViewController.m
//  qiJi
//
//  Created by 凤利史 on 2018/4/2.
//  Copyright © 2018年 sunrose. All rights reserved.
//

#import "HYRootXiaoXiZhongXinViewController.h"

#import "HYRootXiaoXiAnotherViewController.h"
#import "ZJScrollPageView.h"

@interface HYRootXiaoXiZhongXinViewController ()<ZJScrollPageViewDelegate>
@property(strong, nonatomic)NSArray<UIViewController<ZJScrollPageViewChildVcDelegate> *> *childVcs;
@property(strong, nonatomic)NSArray<NSString *> *titles;
@property (weak, nonatomic) ZJScrollSegmentView *segmentView;
@property (weak, nonatomic) ZJContentView *contentView;
@end

@implementation HYRootXiaoXiZhongXinViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationView];
    //self.title = @"消息中心";
    

    // Do any additional setup after loading the view.
}
//设置顶部20的部分字体颜色变为白色
- (UIStatusBarStyle)preferredStatusBarStyle{

    return UIStatusBarStyleLightContent;

}

- (void)creationView{
    UIView *view = [[UIView alloc] init];
    [self.view addSubview:view];
    view.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, (KIsiPhoneX?84:64));
    view.backgroundColor = getColor(@"7C8187");
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    UILabel *titlelabel = [[UILabel alloc] init];
    [view addSubview:titlelabel];
    [titlelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view).with.offset(35);
        make.centerX.equalTo(view);
    }];
    
    titlelabel.text = @"消息中心";
    
    titlelabel.font = [UIFont fontWithName:@"DINEngschrift LT Alternate" size:16];
    
    titlelabel.textColor = [UIColor whiteColor];
    
    
    UIImage *im = [UIImage imageNamed:@"common_back_btn"];
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(20, 35, im.size.width, im.size.height);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"common1_back_btn"] forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"common1_back_btn"] forState:UIControlStateSelected];
    [leftBtn addTarget:self action:@selector(leftNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:leftBtn];
    
    
    
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    //124 129 135
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
//    style.showCover = YES;
//
//    style.coverBackgroundColor =  [UIColor colorWithRed:124 / 255.0f green:129 / 255.0f blue:135 / 255.0f alpha:1];
    style.scrollTitle = YES;
    style.autoAdjustTitlesWidth = YES;
    style.adjustCoverOrLineWidth = YES;
    style.normalTitleColor = [UIColor colorWithRed:255 / 255.0f green:255 / 255.0f blue:255 / 255.0f alpha:1];
    style.selectedTitleColor = [UIColor colorWithRed:255 / 255.0f green:255 / 255.0f blue:255 / 255.0f alpha:1];
    style.scrollLineColor = [UIColor colorWithRed:255 / 255.0f green:209 / 255.0f blue:0 / 255.0f alpha:1];
    style.segmentHeight = 40;
    self.titles = @[@"点赞",
                    @"评论",
                    @"粉丝",
                    @"通知",
                    ];
    
    // 初始化
//    ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, (KIsiPhoneX?84:64), DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - (KIsiPhoneX?84:64)) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
//    [scrollPageView setSelectedIndex:self.indexID animated:YES];
//    scrollPageView.contentView.scrollView.scrollEnabled = YES;
//    [self.view addSubview:scrollPageView];
    
    
    __weak typeof(self) weakSelf = self;
    ZJScrollSegmentView *segment = [[ZJScrollSegmentView alloc] initWithFrame:CGRectMake(-5, (KIsiPhoneX?84:64), DEF_SCREEN_WIDTH+10, 40) segmentStyle:style delegate:self titles:self.titles titleDidClick:^(ZJTitleView *titleView, NSInteger indexID) {
        
        [weakSelf.contentView setContentOffSet:CGPointMake(weakSelf.contentView.bounds.size.width * indexID, 0.0) animated:YES];
        
    }];
    [self.view addSubview:segment];
    segment.backgroundColor = getColor(@"7C8187");
    self.segmentView = segment;
  //  view = self.segmentView;
    
    ZJContentView *content = [[ZJContentView alloc] initWithFrame:CGRectMake(0, (KIsiPhoneX?84:64)+40, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT-(KIsiPhoneX?84:64)) segmentView:self.segmentView parentViewController:self delegate:self];
    
    self.contentView = content;
    [self.view addSubview:self.contentView];
    
    
    // Do any additional setup after loading the view.
}
//返回前一页
-(void)leftNavItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark ----------------ZJScrollPageViewDelegate---------------------
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}
- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    HYRootXiaoXiAnotherViewController <ZJScrollPageViewChildVcDelegate> *childVc = (HYRootXiaoXiAnotherViewController *)reuseViewController;
    
    if (!childVc) {
        
        childVc = [[HYRootXiaoXiAnotherViewController alloc] init];
        
        
        childVc.orderStatus = index;
        
        
        NSLog(@"MMMMMMMMMMMMMM%ld", (long)index);
        
        
    }
    
    return childVc;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
